<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateServiceOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('service_orders', function (Blueprint $table) {
            $table->increments('id');
            $table->string('order_id')->default('')->comment('订单编号');
            $table->string('payment_no')->nullable()->comment('交易单号');
            $table->integer('user_id')->default('0')->comment('用户ID');
            $table->integer('shop_id')->default('0')->comment('门店ID');
            $table->integer('worker_id')->default('0')->comment('师傅ID');
            $table->decimal('amount')->default('0.00')->comment('支付金额');
            $table->decimal('discount')->default('0.00')->comment('折扣系数');
            $table->json('service')->nullable()->comment('服务信息');
            $table->string('service_id')->default('0')->comment('服务ID');
            $table->string('appoint_time')->nullable()->comment('预约上门时间');
            $table->integer('car_id')->default('0')->comment('车辆ID');
            $table->json('car')->nullable()->comment('车辆信息');
            $table->integer('user_coupon_id')->default('0')->comment('优惠券ID');
            $table->integer('user_card_id')->default('0')->comment('用户洗车会员卡ID');
            $table->decimal('coupon_price')->default('0.00')->comment('优惠券抵扣金额');
            $table->string('longitude')->nullable()->comment('用户位置经度');
            $table->string('latitude')->nullable()->comment('用户位置纬度');
            $table->integer('province_id')->default(0)->comment('省ID');
            $table->integer('city_id')->default(0)->comment('市ID');
            $table->integer('district_id')->default(0)->comment('区ID');
            $table->string('address')->nullable()->comment('用户地址信息');
            $table->json('info1')->nullable()->comment('确认时环车检查信息');
            $table->json('info2')->nullable()->comment('完成时环车检查信息');
            $table->tinyInteger('status')->default('0')->comment('状态:0=待上门,1=服务中,2=已完成,3=已评价,4=已取消');
            $table->tinyInteger('state')->default('0')->comment('状态:0=未完成,1=已完成');
            $table->dateTime('order_time')->comment('下单时间');
            $table->dateTime('receive_time')->nullable()->comment('接单时间');
            $table->dateTime('arrive_time')->nullable()->comment('上门时间');
            $table->dateTime('finish_time')->nullable()->comment('完成时间');
            $table->dateTime('cancel_time')->nullable()->comment('取消时间');
            $table->text('remark')->nullable()->comment('备注');
            $table->text('reason')->nullable()->comment('取消原因');
            $table->tinyInteger('is_read')->default(0)->comment('是否阅读');
            $table->tinyInteger('is_apply')->default(0)->comment('是否为取消申请订单 0=否,1=是');
            $table->tinyInteger('pay_way')->default(0)->comment('支付方式');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('service_orders');
    }
}
